package de.stefanocke.roo.kontaktliste.web.common;

import org.apache.wicket.model.IModel;

import de.stefanocke.roo.kontaktliste.web.BasePage;
import de.stefanocke.roo.wicket.RooStereotype;

@RooStereotype("wicket.CrudPage")
public abstract class CrudPage<T> extends BasePage {

	protected static final String DETAILS_ID = "detailsPanel";
	protected static final String FORM_ID = "formPanel";
	protected static final String TABLE_ID = "tablePanel";
	
	private static final long serialVersionUID = 1L;

	public CrudPage() {
		super();

		IEntityBindings<T, ?> bindings = createBindings();
		FormPanel<T> form = createFormPanel(FORM_ID, null, bindings);
		add(form);
		
		DetailsPanel<T> details = createDetailsPanel(DETAILS_ID, null, bindings);
		details.setInnerVisible(false);
		
		add(details);

		TablePanel<T> table = createTablePanel(TABLE_ID, bindings);
		
		add(table);
	}


	@SuppressWarnings("unchecked")
	protected FormPanel<T> getFormPanel() {
		return (FormPanel<T>) get(FORM_ID);
	}

	@SuppressWarnings("unchecked")
	protected DetailsPanel<T> getDetailsPanel() {
		return (DetailsPanel<T>) get(DETAILS_ID);
	}

	@SuppressWarnings("unchecked")
	protected TablePanel<T> getTablePanel() {
		return (TablePanel<T>) get(TABLE_ID);
	}
	



	protected abstract IEntityBindings<T, ?> createBindings();

	protected abstract FormPanel<T> createFormPanel(String id,  IModel<T> model, IEntityBindings<T, ?> serviceBindings);

	protected abstract TablePanel<T> createTablePanel(String id, IEntityBindings<T, ?> serviceBindings);
	
	protected abstract DetailsPanel<T> createDetailsPanel(String id, IModel<T> model, IEntityBindings<T, ?> serviceBindings);

}